﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Register : System.Web.UI.Page
{
    private SqlConnection connect;
    private int acc = '0';
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {

            string connectString = WebConfigurationManager.ConnectionStrings["connect"].ConnectionString;
            connect = new SqlConnection(connectString);
            if (connect.State == ConnectionState.Open)
                connect.Close();
            else
                connect.Open();
            SqlCommand cmd = new SqlCommand("addAccount", connect);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@username", SqlDbType.NVarChar).Value = txtUsername.Text;
            cmd.Parameters.Add("@password", SqlDbType.NVarChar).Value = txtPassword.Text;
            cmd.Parameters.Add("@acctype", SqlDbType.NVarChar).Value = '0';
            cmd.Parameters.Add("@fullname", SqlDbType.NVarChar).Value = txtFullname.Text;
            cmd.Parameters.Add("@sex", SqlDbType.NVarChar).Value = DropDownList1.SelectedValue.ToString();
            cmd.Parameters.Add("@birthday", SqlDbType.NVarChar).Value = Request.Form["datepicker"];
            cmd.Parameters.Add("@add", SqlDbType.NVarChar).Value = txtAddress.Text;
            cmd.Parameters.Add("@phone", SqlDbType.NVarChar).Value = txtPhone.Text;
            cmd.Parameters.Add("@email", SqlDbType.NVarChar).Value = txtEmail.Text;

            cmd.ExecuteNonQuery();
            //upload image on server
            Response.Redirect("Default.aspx");
        }
        catch (SqlException ex)
        {
            throw new Exception(ex.Message);
        }
        finally
        {
            connect.Close();
        }
    }
}